package com.pc.cloud.anlysis;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;

import java.io.IOException;
import java.io.Reader;

public final class OneCharAnalyzer extends Analyzer {

	@Override
	public TokenStream tokenStream(String arg0, Reader arg1) {
		return new OneCharTokenizer(arg1);
	}

	@Override
	public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
		Tokenizer tokenizer = (Tokenizer) getPreviousTokenStream();
	    if (tokenizer == null) {
	      tokenizer = new OneCharTokenizer(reader);
	      setPreviousTokenStream(tokenizer);
	    } else
	      tokenizer.reset(reader);
	    return tokenizer;
	}
}
